package com.leeon.container;

import typeinfo.pets.*;

import java.util.*;

import static net.mindview.util.Print.print;

public class ListFeatures {
    public static void main(String[] args){
        Random random = new Random(47);
        List<Pet> pets = Pets.arrayList(7);
        System.out.println("1:" + pets);
        Hamster h = new Hamster();
        pets.add(h);
        System.out.println("2:" + pets);
        System.out.println("3:" + pets.contains(h));
        pets.remove(h);
        Pet p = pets.get(2);
        System.out.println("4" + p + " " + pets.indexOf(p));
        Pet cymric = new Cymric();
        System.out.println("5: " + pets.indexOf(cymric));
        System.out.println("6: " + pets.remove(cymric));
        System.out.println("7: " + pets.remove(p));
        System.out.println("8: " + pets);
        pets.add(3,new Mouse());
        System.out.println("9: " + pets);
        List<Pet> sub = pets.subList(1,4);
        System.out.println("sublist : " + sub);
        System.out.println("10: " + pets.containsAll(sub));
        Collections.sort(sub);
        System.out.println("sorted sublist: " + sub);
        System.out.println("11: " + pets.containsAll(sub));
        Collections.shuffle(sub,random);
        print("shuffled sublist : " + sub);
        print("12 : " + pets.containsAll(sub));
        List<Pet> copy = new ArrayList<Pet>();
        sub = Arrays.asList(pets.get(1),pets.get(4));
        print("sub: " + sub);
        copy.retainAll(sub);
        print("13: " + copy);
        copy = new ArrayList<Pet>(pets);
        print("13-1 : " + copy);
        copy.remove(2);
        print("14 : " + copy);
        print("14-1 : " + sub);
        copy.removeAll(sub);
        print("15: " + copy);
        copy.set(1,new Mouse());
        print("16: " + copy);
        copy.addAll(2,sub);
        print("17: " + copy);
        print("18: " + pets.isEmpty());
        pets.clear();
        print("19: " + pets);
        print("20: " + pets.isEmpty());
        pets.addAll(Pets.arrayList(4));
        print("21: " + pets);
        Object[] o = pets.toArray();
        print("22: " + o[3]);
        Pet[] pa = pets.toArray(new Pet[0]);
        print("23: "+ pa[3].id());
    }
}
